package com.project2.controller;

import com.project2.bean.CommonData;
import com.project2.bean.PageBo;
import com.project2.bean.ResultVo;
import com.project2.bean.bo.WxFootprintDeleteBo;
import com.project2.bean.po.MarketUser;
import com.project2.bean.vo.BeanInListInDataInWxFootprintListVo;
import com.project2.bean.vo.DataInWxFootprintListVo;
import com.project2.service.WxFootprintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author zhangminghui
 * @date 2022/8/15
 */
@RestController
@RequestMapping("wx/footprint")
public class WxFootprintController {
    @Autowired
    WxFootprintService wxFootprintService;

    @RequestMapping("list")
    public ResultVo list(PageBo pageBo, HttpServletRequest request) {
        String header = request.getHeader("X-CskaoyanMarket-Token");
        MarketUser marketUser = (MarketUser) request.getSession().getAttribute(header);
        Integer userId = marketUser.getId();
        CommonData<BeanInListInDataInWxFootprintListVo> data = wxFootprintService.queryDataInWxFootprintListVo(pageBo,userId);

        return ResultVo.ok(data);
    }

    @RequestMapping("delete")
    public ResultVo delete(@RequestBody WxFootprintDeleteBo wxFootprintDeleteBo) {
        wxFootprintService.deleteFootprintById(wxFootprintDeleteBo.getId());
        return ResultVo.ok();
    }

}
